// vs_get_lcd_buf.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <stdio.h>

typedef unsigned       	char 	u8;
typedef unsigned 		short 	u16;
typedef unsigned       	long 	u32;
typedef signed       	char 	s8;
typedef signed 			short 	s16;
typedef signed       	long 	s32;



u8 dt_buf[128] = { 
    0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,	//0 1 2 3 4 5 6 7 8 9 
    0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x00,0x00,0x00,	//A B C D E F 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x3F,0x06,	//          -     0 1 
    0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00,0x00,	//2 3 4 5 6 7 8 9     
    0x00,0x00,0x00,0x00,0x00,0x77,0x7c,0x39,0x5e,0x79,	//          A B C D E 
    0x71,0x3d,0x76,0x0f,0x0e,0x75,0x38,0x37,0x54,0x5c,	//F G H I J K L M N O
    0x73,0x67,0x50,0x49,0x78,0x3e,0x1c,0x7e,0x64,0x6e,	//P Q R S T U V W X Y 
    0x59,0x00,0x00,0x00,0x00,0x08,0x00,0x77,0x7c,0x39,	//Z         _   A B C 
    0x5e,0x79,0x71,0x3d,0x76,0x0f,0x0e,0x75,0x38,0x37, 	//D E F G H I J K L M
    0x54,0x5c,0x73,0x67,0x50,0x49,0x78,0x3e,0x1c,0x7e,	//N O P Q R S T U V W 
    0x64,0x6e,0x59,0x00,0x06,0x00,0x00,0x00				//X Y Z   |      
};
u8 sort0[8] = { 0,1,2,3,4,5,6,7 };//ABCDEFGH
u8 sort1[8] = { 6,5,4,3,2,1,0,7 };//GFEDCBAH
u8 scanbuf[20] = {0};

u8 out_buf[128];
int main()
{
    u8 i, j, k;
    u8 tmp;

START:
    printf("请按SEG1-7的顺序输入数码管段名称ABCDEFGH：\n");
    scanf_s("%s", &scanbuf,9);

    for (i = 0; i < 8; i++) {
        if (scanbuf[i] > 'H' || scanbuf[i] < 'A') {
            printf("输入错误\n");
            goto START;
        }
        sort1[i] = scanbuf[i] - 0x41;
    }

    for (i = 0; i < 128; i++) {
        out_buf[i] = 0;
        for (j = 0; j < 8; j++) {
            for (k = 0; k < 8; k++) {
                if (sort1[j] == sort0[k]) {
                    tmp = k;
                }
            }
            out_buf[i] |= ((dt_buf[i] & (1 << tmp)) != 0) << j;
        }
        printf("0x%02X,", out_buf[i]);// 
        if ((i+1) % 10 == 0)printf("\n");
    }
    printf("\n\n");
    goto START;

}
